<?xml version = '1.0' encoding = 'UTF-8'?>
<HBRRepo><variables/><rulesets/><rules><rule id="1" name="OQP_BottomUp Adjust Aggregation" product="Planning"><property name="application">SalesPln</property><property name="plantype">OEP_QTP</property><property name="seeded">true</property><script type="groovy">%Template(name:="OQP_BottomUp Aggregation By Account_T",application:="SalesPln",plantype:="OEP_QTP",dtps:=("AggAccount":="OQP_Quota Adjustment Value"))</script></rule></rules><components/><deployobjects><deployobject product="2" application="salespln" plantype="oep_qtp" obj_id="1" obj_type="19" name="OQP_BOTTOMUP AGGREGATION BY ACCOUNT_T"/><deployobject product="2" application="salespln" plantype="oep_qtp" obj_id="1" obj_type="1" name="OQP_BOTTOMUP ADJUST AGGREGATION"/></deployobjects><templates><template custom="yes" id="1" name="OQP_BottomUp Aggregation By Account_T" product="Planning"><property name="application">SalesPln</property><property name="plantype">OEP_QTP</property><property name="seeded">true</property><script type="groovy">			/*PURPOSE: This Template Aggregates Bottom Up Quota accrosss all products */            
            def grid=operation.grid;
			int firstColumn;
			int firstRow;
			String strCrossDim="";
			String rowMembers="";
			String strCrossDimAny="";
			boolean isDataModified=false;
			String driverDimMember;
			boolean isUnitsModel=false;
			List&lt;String> AnyMbrs = [];
			List&lt;String> RowDimensions =[];
			List&lt;String> ColumnDimensions=[];
			List&lt;String> AggDimensions=[];
			List&lt;String> NewColumnDims=[];
			List&lt;String> CustomColumnMbrs=[];
			List&lt;String> fixMemberNames = [];
			try
			{
            /*Eevaluates if application is  by Units or amount */
			  Application app=operation.getApplication();
             Cube qtp=operation.getCube(); 
              Dimension dim=app.getDimension(DimensionType.ACCOUNT,qtp);
              if (dim.hasMember("OQP_Units",qtp)==true)
              {
                isUnitsModel=true;
                driverDimMember="OQP_Last Year Units";
              }
              else
              {
                isUnitsModel=false;
                driverDimMember="OQP_Last Year Revenue";                    
              }
              /*Fetchs list of POV dimensions and their members*/
			List&lt;DataGrid.HeaderCell> pov=grid.getPov()
			for (DataGrid.HeaderCell cell : pov)
			{
			   String mbrName = cell.getEssbaseMbrName();
			   DimensionType dimType = cell.getDimensionType();
			   String dimName=cell.getDimName(); 
			   
				if(dimType==DimensionType.CUSTOM)
				{					
					AggDimensions.add('''"'''+dimName+'''"''')  
					strCrossDim= strCrossDim + "\"OEP_All "+ dimName+"\"->"
					AnyMbrs.add('''"No '''+dimName+'''"''')
					strCrossDimAny=strCrossDimAny + "\"No "+ dimName+"\"->"
				}
				else
				{
					 fixMemberNames.add(mbrName )							
				}
				
			}
			/*Fetchs list of Row dimensions and their members*/
			List&lt;DataGrid.Row> rows = grid.getRows()
			for (DataGrid.Row row : rows) 
			{
				List&lt;DataGrid.HeaderCell> subRows = row.getHeaders();
				for(DataGrid.HeaderCell cell : subRows) 
				  {
					String memName = cell.getDimName();          
				  if (!RowDimensions.contains(memName))
				   {
						RowDimensions.add(memName)             
				   }     	 
				 }        
			}
			/*Fetchs list of column dimensions and their members- It reads first column and first row to identify dimensions and their members*/
			List&lt;List&lt;DataGrid.HeaderCell>> cols = grid.getColumns();
			for (List&lt;DataGrid.HeaderCell> cells : cols) 
			{
			 firstColumn=0;
				for (DataGrid.HeaderCell cell : cells)  
				  {
				   String memName = cell.getMbrName();
				   String dimName = cell.getDimName();
				   if (!ColumnDimensions.contains(dimName))
					  {
						if (!memName.equals("YearTotal") &amp;&amp; !memName.equals(driverDimMember)  )
						{
							ColumnDimensions.add(dimName);    
						   AggDimensions.add('''"'''+dimName+'''"''')   
						   strCrossDim= strCrossDim + "\"OEP_All "+ dimName+"\"->"
						   AnyMbrs.add('''"No '''+dimName+'''"''')
						   strCrossDimAny=strCrossDimAny + "\"No "+ dimName+"\"->"
						 }       
					 }
				   firstColumn++;
				  if (firstColumn==1) 
				  break;
				 }     
			 }			 
			 StringBuilder cscript = new StringBuilder();
             /*Begin of the calc script*/
			cscript.append('''SET AGGMISSG ON;\n''')
			cscript.append('''SET UPDATECALC OFF;\n''')
			firstRow=0;
            /*gets list of roew for which numbers are modified */
			for(String dimName:RowDimensions)
			{
				def ls=operation.grid.dataCellIterator{DataCell cell -> cell.edited}.collect([] as Set,{ DataCell cell ->
				cell.getMemberName(dimName)
				})
				if (ls.size()>0)
					{
						isDataModified=true;
					  if (firstRow==0)
					  {
					  rowMembers=ls.join('''","''');
					  }
					}
				firstRow++;
				  
			}
            /*Aggregation fix*/
			cscript.append('''FIX(''')
			cscript.append('''"'''+fixMemberNames.join('''","''')+'''"''')
			cscript.append(''',"'''+rowMembers+'''"''')
			cscript.append(''',@Relative(Yeartotal,0))\n''')
			cscript.append('''	FIX([AggAccount])\n''')
			if (RowDimensions.size()==2)
			{
			/*cscript.append('''AGG("'''+RowDimensions[1]+'''");\n''')*/
			AggDimensions.add('''"'''+RowDimensions[1]+'''"''');
			}
			cscript.append('''		AGG('''+AggDimensions.join(''',''')+''');\n''')
			cscript.append('''	ENDFIX\n''')
            /*Assigns totals values to Any member*/
			if (RowDimensions.size()==2)
			{
			cscript.append('''	FIX(@RELATIVE("OEP_All '''+RowDimensions[1]+'''",0),'''+AnyMbrs.join(''',''')+''')\n''')
			cscript.append('''		[AggAccount]='''+strCrossDim+'''[AggAccount];\n''');
			cscript.append('''	ENDFIX\n''')
			}
			else
			{
			cscript.append('''	FIX('''+AnyMbrs.join(''',''')+''')\n''')
			cscript.append('''		[AggAccount]='''+strCrossDim+'''[AggAccount];\n''');
			cscript.append('''	ENDFIX\n''');
			}
			cscript.append('''ENDFIX\n''')
			if (isDataModified==true) 
			{
			println (cscript.toString())
			return cscript.toString();
			}
			}catch(all) {
				throw new HspRuntimeException('Error occured while executing business rule');
			    } 
		
		 
		</script><template_wizard><wizard_step name="Default" seq="0"><template_prompts><template_prompt name="AggAccount"/></template_prompts></wizard_step></template_wizard><template_prompts><restricted_prompt name="Application Type" type="Application Type" isPrompt="no"><property name="is_system">true</property><restricted_prompt_item><property name="prompt">Is Generic</property><property name="value">GENERAL</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is PFP</property><property name="value">PROJECT</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is PSB</property><property name="value">PSB</property></restricted_prompt_item></restricted_prompt><restricted_prompt name="Application" type="Application" isPrompt="no"><property name="is_system">true</property><value>Is Single Currency</value><restricted_prompt_item><property name="prompt">Is Multi Currency</property><property name="value">multi</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is Single Currency</property><property name="value">single</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is Simple Currency</property><property name="value">simple</property></restricted_prompt_item></restricted_prompt><template_slice_prompt name="UpperPOV" type="Member Range" isPrompt="false"><property name="is_system">true</property></template_slice_prompt><restricted_prompt name="Essbase Mode" type="Essbase Mode" isPrompt="no"><property name="is_system">true</property><restricted_prompt_item><property name="prompt">Is Hybrid</property><property name="value">Hybrid</property></restricted_prompt_item><restricted_prompt_item><property name="prompt">Is NonHybrid</property><property name="value">NonHybrid</property></restricted_prompt_item></restricted_prompt><template_prompt name="AggAccount" type="Member" isPrompt="true"><property name="dimension">Measures</property><property name="isMandatory">true</property><property name="prompt_text">Enter Aggregation Account</property></template_prompt></template_prompts></template></templates></HBRRepo>